//
//  TravelTactic_RegionViewController.m
//  BTRIP
//
//  Created by Rain on 15/11/16.
//  Copyright © 2015年 johnbk. All rights reserved.
//

#import "TravelTactic_RegionViewController.h"
#import "DataHandle.h"
#import "TravelTactic_RegionModel.h"
#import "TravelTactic_RegionTableViewCell.h"
#import "SpecialDetailViewController.h"

@interface TravelTactic_RegionViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, retain) UITableView *tableView;

@property (nonatomic, retain) NSMutableArray *modelArr;

@end

@implementation TravelTactic_RegionViewController

- (void)dealloc {
    [_urlStr release];
    [_tableView release];
    [_modelArr release];
    
    [super dealloc];
}

- (void)viewWillAppear:(BOOL)animated {
    [self.navigationController.navigationBar setHidden:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.modelArr = [NSMutableArray array];
    
    
    
    
    [self dataload_Region];
    
    [self createTableView_Region];
    
    
}

- (void)dataload_Region {
    [DataHandle contectWithURL:_urlStr andParameters:nil andViewController:self andBlock:^(id response) {
        for (NSDictionary *tempDic in response) {
            TravelTactic_RegionModel *model = [[TravelTactic_RegionModel alloc] init];
            [model setValuesForKeysWithDictionary:tempDic];
            [self.modelArr addObject:model];
            [model release];
        }
        [self.tableView reloadData];
    }];
}

- (void)createTableView_Region {
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, KWIDTH, KHEIGHT) style:UITableViewStyleGrouped];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
    [self.tableView registerClass:[TravelTactic_RegionTableViewCell class] forCellReuseIdentifier:@"regionCell"];
}

#pragma mark 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _modelArr.count;
}

#pragma mark 数据
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TravelTactic_RegionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"regionCell" forIndexPath:indexPath];
    cell.regionModel = _modelArr[indexPath.row];
    return cell;
}

#pragma mark 点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    SpecialDetailViewController *detailVC = [[SpecialDetailViewController alloc] init];
    detailVC.urlStr = [NSString stringWithFormat:@"http://chanyouji.com/api/articles/%@.json?page=1", [_modelArr[indexPath.row] ID]];
    [self.navigationController pushViewController:detailVC animated:YES];
    
    [detailVC release];
    
}

#pragma mark 返回高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 230 * SWIDTH;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
